package com.kust.smarthome.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kust.smarthome.web.dto.CommodityDto;
import com.kust.smarthome.web.mapper.CommodityMapper;
import com.kust.smarthome.web.model.Commodity;
import com.kust.smarthome.web.service.ICommodityService;
import com.kust.smarthome.web.vo.CommodityByTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements ICommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public PageInfo<CommodityDto> page4Dto(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CommodityDto> list = commodityMapper.getCommodityDtoList();
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<CommodityDto> select4Dto(String nameInfo, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CommodityDto> list = commodityMapper.selectCommodityDtoListByName(nameInfo);

        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<CommodityDto> select4DtoByType(CommodityByTypeVo commodityByTypeVo) {
        PageHelper.startPage(commodityByTypeVo.getPageNum(), commodityByTypeVo.getPageSize());

        List<CommodityDto> list = commodityMapper.selectCommodityDtoListByType(commodityByTypeVo.getType());

        return new PageInfo<>(list);
    }
}
